package example.basic;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mvel.MVEL;

import example.MVELTest;

public class IfElseExample {
	private static Log log = LogFactory.getLog(MVELTest.class);
	public static void main(String[]args) {
		Map vars = new HashMap();
		
		StringBuffer sb = new StringBuffer();
		sb.append("if (myVar > 0)\n");
		sb.append("{\n");
		sb.append("System.out.println('Great than 0.');\n");
		sb.append("}\n");
		sb.append("else if (myVar < 0)\n");
		sb.append("{\n");
		sb.append("System.out.println('Less than 0.');\n");
		sb.append("}\n");
		sb.append("else\n");
		sb.append("{\n");
		sb.append("System.out.println('Equals 0.');\n");
		sb.append("}\n");
		log.info(sb.toString());
		vars.put("myVar", new Integer(100));
		log.info(MVEL.eval(sb.toString(), vars));
		
		vars.put("myVar", new Integer(-100));
		log.info(MVEL.eval(sb.toString(), vars));
		
		vars.put("myVar", new Integer(0));
		log.info(MVEL.eval(sb.toString(), vars));
	}
}
